<?php
namespace app\admin\model;

use think\Model;

class AdminRole extends Model {

    protected $pk = 'role_id';

    public function getRoleList($where, $listRows=10,$params=[]){

        return $this->where($where)->order('role_id desc')->paginate($listRows,false,['query'=>$params]);
    }

    //获取所有的角色
    public function getAll(){
        $where[] = ['is_del','=',0];
        return $this->where($where)->field('role_id,role_name')->select();
    }

    // 写入一条数据
    public function insertOne($data){
        $data['create_time'] = time();
        $data['is_del'] = 0;
        return $this->insertGetId($data);
    }


    public function getOne($role_id){

        return $this->where('role_id','=',$role_id)->findOrFail();
    }

    // 软删除一条数据
    public function delOne($role_id){

        $data['is_del'] = 1;
        return $this->where('role_id','=',$role_id)->update($data);
    }

    // 更新一条数据
    public function updateOne($role_id,$data){

        return $this->where('role_id','=',$role_id)->update($data);
    }


}